package com.summer.content.api;

import com.summer.content.service.TeachPlanService;
import com.summer.dto.SaveTeachPlanDto;
import com.summer.dto.TeachPlanDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(value = "课程计划API", tags = "课程计划API")
@RestController
@Slf4j
public class TeachPlanController {


    @Autowired
    private TeachPlanService teachPlanService;

    /**
     *
     * @param courseId 课程id
     * @return 返回课程计划及其关联视频信息dto
     */
    @ApiOperation(value = "根据课程id查询课程计划")
    @GetMapping("teachplan/{courseId}/tree-nodes")
    @ApiImplicitParam(name = "courseId", value = "课程id", required = true)
    public List<TeachPlanDto> getCoursePlanById(@PathVariable Long courseId){
        log.info("根据课程id查询课程计划，courseId= {}", courseId);
        return teachPlanService.getCoursePlanById(courseId);
    }


    @ApiOperation(value = "保存课程计划")
    @PostMapping("teachplan")
    public void saveTeachPlan(@RequestBody @Validated SaveTeachPlanDto saveTeachPlanDto){
        log.info("保存课程计划，saveTeachPlanDto= {}", saveTeachPlanDto);
        teachPlanService.saveTeachPlan(saveTeachPlanDto);
    }

    @ApiOperation(value = "根据id删除课程计划")
    @DeleteMapping("teachplan/{id}")
    @ApiImplicitParam(name = "id", value = "课程计划id", required = true)
    public void deletePlan(@PathVariable Long id){
        log.info("根据id删除课程计划, id = {}", id);
        teachPlanService.deletePlan(id);
    }

    @ApiOperation(value = "根据id下移课程计划")
    @PostMapping("teachplan/movedown/{id}")
    public void movedown(@PathVariable Long id){
        log.info("根据id下移课程计划, id = {}", id);
        teachPlanService.movedown(id);
    }

    @ApiOperation(value = "根据id上移课程计划")
    @PostMapping("teachplan/moveup/{id}")
    public void moveup(@PathVariable Long id){
        log.info("根据id上移课程计划, id = {}", id);
        teachPlanService.moveup(id);
    }
}
